//
//  YSTopicItemView.m
//  Yueshi
//
//  Created by yueshi－mac1 on 15/12/8.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSTopicItemView.h"
#import "YSTopicItemToolView.h"

@interface YSTopicItemView()
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) YSTopicItemToolView *toolView;
@property (strong, nonatomic) UIView *spliteView;

@end


@implementation YSTopicItemView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UILabel *nameLabel = [[UILabel alloc] init];
        [nameLabel setFont:SYS_FONT(kNameFont)];
        [nameLabel setTextColor:publicTextColor];
        [self addSubview:nameLabel];
        _nameLabel = nameLabel;
        
        UIImageView *imageView = [[UIImageView alloc]init];
        CGFloat imageWidth = SCREENW - YSPublicXInset *2;
        [imageView setSize:CGSizeMake(imageWidth, imageWidth * 500/710)];
        [self addSubview:imageView];
        _imageView = imageView;
        
        YSTopicItemToolView *toolView = [YSTopicItemToolView toolView];
        [self addSubview:toolView];
        _toolView = toolView;
        
        UIView *spliteView = [[UIView alloc]init];
        [spliteView setBackgroundColor:PUBLIC_BG];
        [self addSubview:spliteView];
        _spliteView = spliteView;
        
    }
    return self;
}

- (void)setItemFrame:(YSTopicItemFrame *)itemFrame{
    _itemFrame = itemFrame;
    
    YSReviews *reviews = itemFrame.reviews;
    
    _nameLabel.text = reviews.postName;
    _nameLabel.frame = itemFrame.nameFrame;
    
    [_imageView setImageURLStr:reviews.imgList];
    _imageView.x = itemFrame.imageFrame.origin.x;
    _imageView.y = itemFrame.imageFrame.origin.y;
    
    _toolView.frame = itemFrame.toolFrame;
    _toolView.isPraise = reviews.isLike;
    
    YSShareModel *sm = [YSShareModel new];
    [sm setUrl:reviews.shareLinks];
    [sm setImageUrl:reviews.imgList];
    [sm setTitle:reviews.postName];
    [sm setSubTile:reviews.summary];
    [_toolView setShareModel:sm];

    _spliteView.frame = itemFrame.spliteFrame;
    
    self.frame = itemFrame.frame;
}

- (void)setIndexPath:(NSIndexPath *)indexPath{
    _toolView.indexPath = indexPath;
}

@end
